import axios from 'axios'
import { getToken } from './token'

const axiosInstance = axios.create({
  baseURL: process.env.BASE_API,
  timeout: 5000
})

axiosInstance.interceptors.request.use(config => {
  let token = getToken()
  if (token) {
    config.headers['token'] = token
  }
  return config
}, error => {
  console.log(error)
  Promise.reject(error)
})

axiosInstance.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)

export default axiosInstance
